<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<title>消息推送</title>
    <script src="__JS__/zepto.min.js"></script>
    <link href="__CSS__/weui.min.css" rel="stylesheet">
	<link rel="stylesheet" href="__SaleManager__/stylesheets/index.css">
</head>
<body>
	<div class="pushHistory">
		<header class = "all_header">
			<a class = "h_back h_back_1"  data-role-id='{$myself.role_id}' href="javascript:void(0)"><img src="__SaleManager__/images/back_icon.png" alt=""></a>
			<span class = "h_title">消息推送</span>
			<a class = "h_add" href="javascript:void(0)"></a>
		</header>
		<div class="page">
	    <div class="page__bd" style="height: 100%;">
	        <div class="weui-tab">
	            <div class="weui-navbar">
	              <div class="weui-navbar__item weui-bar__item_on">
	                  推送消息
	              </div>
	              <div class="weui-navbar__item">
	                  推送历史
	              </div>
	            </div>
	            <div class="weui-tab__panel">
								<div class="push_list" style = "display: block;">
									<div class="weui-cells__title">请选择推送对象</div>
									<div class="weui-cells">
				                <div class="weui-cell__bd">
                                    &nbsp;
                                    <volist name="push_info" id="vo">
                                        <eq name="vo" value="0"><input type="checkbox" name="rrole_id" value="0" checked>全部总部</eq>
                                        <eq name="vo" value="1"><input type="checkbox" name="rrole_id" value="1" checked>全部大区经理</eq>
                                        <eq name="vo" value="2"><input type="checkbox" name="rrole_id" value="2" checked>全部省总</eq>
                                        <eq name="vo" value="11"><input type="checkbox" name="rrole_id" value="11" checked>全部大区助理</eq>
                                        <eq name="vo" value="3"><input type="checkbox" name="rrole_id" value="3" checked>全部地总</eq>
                                        <eq name="vo" value="4"><input type="checkbox" name="rrole_id" value="4" checked>全部县总</eq>
                                        <eq name="vo" value="5"><input type="checkbox" name="rrole_id" value="5" checked>全部业务员</eq>
                                        <eq name="vo" value="6"><input type="checkbox" name="rrole_id" value="6" checked>全部销售部</eq>
                                        <eq name="vo" value="7"><input type="checkbox" name="rrole_id" value="7" checked>全部事业部</eq>
                                        <eq name="vo" value="8"><input type="checkbox" name="rrole_id" value="8" checked>全部诊所</eq>
                                    </volist>
				                </div>
					            </div>

					        <div class="weui-cells__title">请选择推送分类</div>
									<div class="weui-cells">
					          <div class="weui-cell weui-cell_select">
				                <div class="weui-cell__bd">
			                    <select class="weui-select" name="select2">
			                        <option selected="" value="1">普通消息</option>

			                    </select>
				                </div>
					            </div>
					        </div>
					        <div class="weui-cells__title">推送标题</div>
									<div class="weui-cells" style = "padding: 10px 15px;">
					            <div class="weui-cell">
				                <div class="weui-cell__bd">
				                  <input class="weui-input" id="title" name="title" maxlength="20" type="text" placeholder="请输入标题(20字以内)">
				                </div>
					            </div>
					        </div>
					        <div class="weui-cells__title">编辑推送内容</div>
					        <div class="weui-cells weui-cells_form">
					            <div class="weui-cell" style = "padding: 10px 15px;">
					                <div class="weui-cell__bd">
					                    <textarea class="weui-textarea" id="txt" name="txt" placeholder="请输入文本" rows="3"></textarea>
					                </div>
					            </div>
					        </div>
			            <div class="weui-btn-area">
							      <a class="weui-btn push_btn" id="add">发 送</a>
							    </div>
								</div>
								<div class="push_list">
                                    <volist name="push" id="vo">
									<div class="weui-panel weui-panel_access">
				                    <div class="weui-panel__bd">
				                    <div class="weui-media-box weui-media-box_text">
				                    <div class="weui-media-box__title">
				                    	<div>
                                            <span class = "all_user">所有推送用户</span>
				                    		<span class = "infos">普通消息</span>
				                    	</div>
				                    	<div class = "nav_btn" data-id="{$vo.id}">删除</div>
				                    </div>
                                        <p>{$vo.title}</p>
				                    <p class="weui-media-box__desc">{$vo.content}</p>
				                    <div class = "push_date_w">
				                    	<span>{$vo.date}</span>
				                    	<span class = "push_state">已完成</span>
				                    </div>
				                </div>
				            </div>
					        </div>
                                    </volist>
								</div>
	            </div>
		        </div>
		    </div>
		</div>
	</div>
	<script src = "__SaleManager__/js/androidback.js"></script>
	<script src = "__SaleManager__/js/index.js"></script>
    <script type="text/javascript" src="/Public/Patient/js/layer_mobile/layer.js"></script>
    <script type="text/javascript">
        $(function(){
            //保存事件
            var issend = false;
            $('#add').click(function(){
                if(issend) return false;
                issend = true;
                var checkboxValue= new Array();
                var checkboxStr=document.getElementsByName("rrole_id");
                for(var i=0; i<checkboxStr.length; i++){
                    if(checkboxStr[i].checked==true){
                        checkboxValue.push(checkboxStr[i].value);
                    }else{
                        issend = false;
                        layer_msg('请选择推送对象');
                        return false;
                    }
                }
                var rrole_id=checkboxValue;
                var title=$('#title').val();
                if(!title){
                    issend = false;
                    layer_msg('标题不能为空');
                    return false;
                }
                var txt=$('#txt').val();
                if(!txt){
                    issend = false;
                    layer_msg('内容不能为空');
                    return false;
                }
                var url=location.href;
                $.post(location.href,{rrole_id:rrole_id,title:title,txt:txt},function (data){
                    issend = false;
                    if(data.code==0){
                        layer_msg('发送成功',1,function(){
                        	url=newBackByRole($('.h_back_1').attr('data-role-id'),'index');
                        	location.href=url;
                        });
                    }else{
                        layer_msg(data.msg);
                    }
                },'json');
            });
        });
        //统一的layer提示弹层
        function layer_msg(msg,time,func){
            if(typeof time == 'undefined') time=2;
            if(typeof func != 'function') func=function(){};
            layer.open({
                content: msg
                ,skin: 'msg'
                ,time: time
                ,end: func()
            });
        }
        
        function newBackByRole(roleId,url){
			switch(parseInt(roleId)){
			case 0:
				url= "/Home/SaleManager/Head/"+url; //总部
				break;	
			case 1:
				url= "/Home/SaleManager/Salemanager/"+url; //大区经理
				break;
			case 11:
				url= "/Home/SaleManager/Salemanager/indexassistant"; //大区经理助理
				break;
			case 2:
				url= "/Home/SaleManager/Province/"+url;//省总
				break;
			case 3:
				url= "/Home/SaleManager/City/"+url;//地总
				break;
			case 4:
				url= "/Home/SaleManager/County/"+url;//县总
				break;
			case 6:
				url= "/Home/SaleManager/Saledepartment/"+url;//销售部
				break;
			case 7:
				url= "/Home/SaleManager/Career/"+url;//事业部
				break;
			default:url= "/Home/Saleman/Saleman/"+url;//业务员
			}
			return url;
		}
    </script>
</body>
</html>